<template>
  <div class="app-container">
    <!-- 底部导航栏 -->
    <div class="bottom-nav">
      <div
        v-for="(item, index) in navItems"
        :key="index"
        class="nav-item"
        :class="{ active: currentPath === item.path }"
        @click="navigateTo(item.path)"
      >
        <img :src="require(`@/assets/icon/${item.icon}`)" :alt="item.label" class="icon" />
        <span>{{ item.label }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, watch} from 'vue';
import { useRouter, useRoute } from 'vue-router';

const router = useRouter();
const currentPath = ref(router.currentRoute.path);

const route = useRoute();
watch(
  () => route.path, // 观察的源
  (newPath) => {
    currentPath.value = newPath;
  },
  { immediate: true } // 设置 immediate 为 true
);
// 导航项定义
const navItems = [
  { path: '/main', icon: 'list.png', label: '主页' },
  { path: '/chat', icon: 'chat.png', label: '聊天' },
  { path: '/settings', icon: 'setting.png', label: '设置' }
];

// 切换路径
function navigateTo(path) {
  router.push(path);
}
</script>

<style scoped>
/* 整个应用容器 */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  justify-content: space-between;
  align-items: center;
}

/* 底部导航栏 */
.bottom-nav {
  display: flex;
  flex-direction: column; /* 将子元素垂直排列 */
  align-items: center; /* 子元素靠左对齐 */
  justify-content: flex-start; 
  position: fixed;
  bottom: 0;
  left: 0;
  gap: 10vh;
  width: 5vw; /* 设置导航栏的宽度 */
  background: rgba(245, 245, 245, 0.8);
  backdrop-filter: blur(10px); /* 应用模糊效果 */
  -webkit-backdrop-filter: blur(10px); /* 适用于 Safari */
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  height: 100%; /* 导航栏高度占满整个屏幕 */
  padding: 10px 0;
  z-index: 1000;
  transition: background 0.3s ease, transform 0.3s ease-in-out;
}
.bottom-nav::before {
  content: "";
  width: 100%;
  height:1vh; /* 为第一个子元素留出空间 */
}
/* 每个导航项 */
.nav-item {
  flex: 1;
  text-align: center;
  cursor: pointer;
  color: #333; /* 文字颜色 */
  transition: color 0.3s ease, transform 0.3s ease-in-out;
  display: flex;
  flex-direction: column;
  justify-content: center; /* 垂直居中 */
  align-items: center; /* 水平居中 */
  max-height:40px;
}

.nav-item:hover img {
  color: rgba(255, 255, 255, 0.8);
  transform: scale(1.3);
}

.nav-item:hover {
  color: #333333;
}

/* 激活状态样式 */
.nav-item.active {
  color: #333333; 
  font-weight: bold; /* 加粗 */
  
}

.nav-item.active img {
  transform: scale(1.3);
}

/* 图标样式 */
.nav-item img {
  display: block;
  width: 48px;
  height: 48px;
  margin-bottom: 5px;
  transition: transform 0.3s ease;
}

/* 响应式设计：适应小屏幕 */
@media (max-width: 768px) {
  .nav-item img {
    width: 40px;
    height: 40px;
  }
}

@media (max-width: 480px) {
  .nav-item img {
    width: 30px;
    height: 30px;
  }
}
@media (max-width: 768px) and (orientation: portrait) {
.bottom-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-direction: row; 
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 5vh;
  padding: 10px 0;
  gap: 10vw;
}
.bottom-nav::before {
  display:none;
}
.nav-item {
  flex: 1;
  text-align: center;
  cursor: pointer;
  color: white;
  transition: color 0.3s ease, transform 0.3s ease-in-out;
  display: flex;
  flex-direction: column;
  justify-content: center; /* 垂直居中 */
  align-items: center; /* 水平居中 */
}
}
</style>
